
//## 대시보드 표시 ####################
function fnDrawCalendar(Month, startDay, endDate, curDate, nextMonth, prevMonth)
{
	var calBody = "";
	var mnth = Month.replace("-","");
	var curDt = curDate.split("-").join("");
	for(k=1; k<startDay; k++)
	{
		var sun = "";
		if (k==1) sun = " style=\"border-bottom:2px #ff0000 solid;background-color:#fff0f0\"";
		calBody += "<div class=\"calCellBody\""+sun+">&nbsp;</div>";
	}
	for(d=1; d<=endDate; d++)
	{
		var sun = " style=\"overflow-y:auto;\"";
		var curD = (k+d-1)%7;
		var vD = "";
		if (d<10) vD = "D"+mnth+"0"+d;
		else vD = "D"+mnth+d;
		var showD = d;
		if (curD==1) sun = " style=\"border-bottom:2px #ff0000 solid;background-color:#fff0f0;overflow-y:auto;\"";
		if (vD == "D"+curDt) { sun = " style=\"background-color:#fff8f0;overflow-y:auto;\""; showD = "[<b>"+d+"</b>]"; }
		if (d == endDate)  sun = " style=\"border-right:1px #abccf8 solid;overflow-y:auto;\"";
		if (showD < 10) var curVDt = Month+"-0"+showD;
		else var curVDt = Month+"-"+showD;
		if (curD == 0) calBody += "<div id=\""+vD+"\" class=\"calCellBodyLast\""+sun+"><a href=\"javascript:fnShowOffDayWork('"+curVDt+"')\">"+showD+"</a></div>";
		else calBody += "<div id=\""+vD+"\" class=\"calCellBody\""+sun+"><a href=\"javascript:fnShowOffDayWork('"+curVDt+"')\">"+showD+"</a></div>";
	}
	Month = "<span class=\"normal\" onClick=\"fnGoMonth('"+prevMonth+"')\" style=\"cursor:pointer\"><<</span> &nbsp; "+Month+" &nbsp; <span class=\"normal\" onClick=\"fnGoMonth('"+nextMonth+"')\" style=\"cursor:pointer\">>></span>";
	$("#"+"calendarBody").html(calBody);
	$("#"+"calMonth").html(Month);
}

function fnGoMonth(mnth)
{
	$("#findMonth").val(mnth);
	fnShowCalendar();
}

function fnShowCalendar()
{
	var valUrl = "/action/dashBoard/calendar.asp";
	var param = "findMonth="+encodeURIComponent($("#findMonth").val());
		param += "&findProcType="+$("#findProcType").val();

	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());
			var mnth = $(xml).find("stdMonth").text();
			var startDay = $(xml).find("startDay").text();
			var endDate = $(xml).find("endDate").text();
			var curDate = $(xml).find("curDate").text();
			var nextMonth = $(xml).find("nextMonth").text();
			var prevMonth = $(xml).find("prevMonth").text();
			$("#"+"curMonthBad").html($(xml).find("RateCurMonth").text());
			$("#"+"prevMonthBad").html($(xml).find("RatePrevMonth").text());
			fnDrawCalendar(mnth, startDay, endDate, curDate, nextMonth, prevMonth);
			mnth = mnth.replace("-","");
			for (p=1; p<=endDate; p++)
			{
				var idNm = "";
				if (p<10) idNm = "D"+mnth+"0"+p;
				else  idNm = "D"+mnth+p;
				//if (p<10) alert(idNm + "/" + $(xml).find(idNm).text());
				$("#"+idNm).append("<br>"+$(xml).find(idNm).text());
			}
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

function fnShowOffDayWork(dt)
{
	$("#findProcType").val("offwork");
	$("#workDt").val(dt);
	$("#offDayWorks").css("top",232);
	$("#offDayWorks").css("left",362);
	$("#offDayWorks").show('slow');
	fnShowCalendar();
}

//## 휴일근무  정보 저장 ####################
function fnOffSave()
{
	if (!$("#userId").val())
	{
		alert("근무자를 바르게 선택해 주세요!");
		$("#userId").focus();
		return;
	}
	if (!$("#workDt").val())
	{
		alert("근무일자를 바르게 입력해 주세요!");
		$("#workDt").focus();
		return;
	}
	if (!$("#workTm").val())
	{
		alert("근무 시간을 바르게 입력해 주세요!");
		$("#workTm").focus();
		return;
	}
	var valUrl  = '/action/offDayWork/save.asp';
	var param  = "userId="+$("#userId").val();
		param += "&workDt="+$("#workDt").val();
		param += "&workTm="+$("#workTm").val();
		param += "&seq=";
		param += "&flag=Y";
	
	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			fnSessionCheck($(xml).find("MSG").text());
			if ($(xml).find("MSG").text() == "Save OK!")
			{
				alert("Save OK!");
				fnOffReset();
				fnShowCalendar();
			}
			else alert($(xml).find("MSG").text());
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

function fnOffReset()
{
	$("#workDt").val("");
	$("#workTm").val("");
	$("#userId").val("");

	fnShowCalendar();
}

function fnOffClose()
{
	fnOffReset();
	$("#offDayWorks").css('display',"none");
}
//## 검색 Reset 기능
function fnSearchReset()
{
	$("#findMonth").val("");
}